package com.api.shopapi.service.impl;

import com.api.shopapi.entity.Goods;
import com.api.shopapi.entity.dto.GoodsDTO;
import com.api.shopapi.mapper.GoodsMapper;
import com.api.shopapi.service.GoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author maochuan
 */
@Service("GoodsServiceImplOne")
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;


    @Override
    public int insert(Goods goods) {
      return   goodsMapper.insert(goods);
    }

    @Override
    public int update(Goods goods) {
       return goodsMapper.update(goods);
    }

    @Override
    public List<GoodsDTO> getByGovernmentCode(String governmentCode) {
        return goodsMapper.getByGovernmentCode(governmentCode);
    }

    @Override
    public PageInfo<GoodsDTO> getByGovernmentCodeForPage(int pageIndex, int pageSize,String governmentCode, String name) {
        PageHelper.startPage(pageIndex,pageSize);
        List<GoodsDTO> goodsDTOList =goodsMapper.getByGovernmentCodeAndName(governmentCode,name);
        return new PageInfo<>(goodsDTOList);
    }


    @Override
    public Goods getByName(String name,String governmentCode) {
        return goodsMapper.getByName(name,governmentCode);
    }

    @Override
    public GoodsDTO getByGoodsCode(String goodsCode) {
        return goodsMapper.getByGoodsCode(goodsCode);
    }

    @Override
    public List<GoodsDTO> getByGoodsClassBusinessCode(String goodsClassBusinessCode) {
        return goodsMapper.getByGoodsClassBusinessCode(goodsClassBusinessCode);
    }

    @Override
    public PageInfo<GoodsDTO> getByBusinessCode(int pageIndex, int pageSize, String businessCode, int status, String name,int isRecommend,
                                                int isDelete, int isBargainPrice,String goodsClassGovernmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<GoodsDTO> goodsDTOList =goodsMapper.getByBusinessCode(businessCode, status, name,isRecommend,isDelete,isBargainPrice,goodsClassGovernmentCode);
        return new PageInfo<>(goodsDTOList);
    }

    @Override
    public PageInfo<GoodsDTO> getPageByGovernmentCode(int pageIndex, int pageSize, String governmentCode, String name, int isRecommend, int isDelete, int isBargainPrice,String goodsClassGovernmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<GoodsDTO> goodsDTOList=goodsMapper.getPageByGovernmentCode(governmentCode,name,isBargainPrice,isDelete,isRecommend,goodsClassGovernmentCode);
        return new PageInfo<>(goodsDTOList);
    }

    @Override
    public PageInfo<GoodsDTO> getByGovernmentCode1(int pageIndex, int pageSize, String governmentCode, String name,String goodsClassGovernmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<GoodsDTO> goodsDTOList =goodsMapper.getByGovernmentCode1(governmentCode, name,goodsClassGovernmentCode);
        return new PageInfo<>(goodsDTOList);
    }

    @Override
    public
    PageInfo<Goods> PageByGovernmentCodeBusinessCode(int pageIndex, int pageSize, String governmentCode, String businessCode){
        PageHelper.startPage(pageIndex,pageSize);
        List<Goods> goodsDTOList =goodsMapper.ListByGovernmentCodeBusinessCode(governmentCode, businessCode);
        return new PageInfo<>(goodsDTOList);
    }

    @Override
    public
    PageInfo<Goods> PageByGovernmentCodeBusinessCodePad(int pageIndex, int pageSize,
                                                        String governmentCode, String businessCode){
        PageHelper.startPage(pageIndex,pageSize);
        List<Goods> goodsDTOList =goodsMapper.ListByGovernmentCodeBusinessCodePad(governmentCode, businessCode);
        return new PageInfo<>(goodsDTOList);
    }


    @Override
    public PageInfo<GoodsDTO> getByGoodsClassGovernmentCode(int pageIndex, int pageSize, String goodsClassGovernmentCode, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<GoodsDTO> goodsDTOList = goodsMapper.getByGoodsClassGovernmentCode(goodsClassGovernmentCode, governmentCode);
        return new PageInfo<>(goodsDTOList);
    }

    @Override
    public PageInfo<GoodsDTO> getFirstGoodsClass(int pageIndex, int pageSize, String goodsClassCode, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<GoodsDTO> goodsDTOList = goodsMapper.getFirstGoodsClass(goodsClassCode, governmentCode);
        return new PageInfo<>(goodsDTOList);
    }

    @Override
    public PageInfo<GoodsDTO> getByGoodsName(int pageIndex, int pageSize, String name, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<GoodsDTO> goodsDTOList = goodsMapper.getByGoodsName(name, governmentCode);
        return new PageInfo<>(goodsDTOList);
    }

    @Override
    public
    List<GoodsDTO> getListByBusinessCodeKey(String businessCode, String key){
        return goodsMapper.getListByBusinessCodeKey(businessCode,key);
    }

    @Override
    public List<Goods> getGoods() {
        return goodsMapper.getGoods();
    }



    /**
     * 商家的正常商品列表
     * */
    @Override
    public
    PageInfo<Goods> PageByBusinessCodeNormal(int pageIndex, int pageSize, String businessCode,
                                             String name,int status,String goodsClassGovernmentCode){
        PageHelper.startPage(pageIndex,pageSize);
        List<Goods> goodsDTOList = goodsMapper.ListByBusinessCodeNormal(businessCode,name,status,goodsClassGovernmentCode);
        return new PageInfo<>(goodsDTOList);
    }


    /**
     * 商家删除的商品列表
     * */
    @Override
    public
    PageInfo<Goods> PageByBusinessCodeDelete(int pageIndex, int pageSize, String businessCode, String name){
        PageHelper.startPage(pageIndex,pageSize);
        List<Goods> goodsDTOList = goodsMapper.ListByBusinessCodeDelete(businessCode,name);
        return new PageInfo<>(goodsDTOList);
    }


    /**
     * 商家收银机的商品列表
     * */
    @Override
    public
    PageInfo<Goods> PageByBusinessCodePad(int pageIndex, int pageSize, String businessCode){
        PageHelper.startPage(pageIndex,pageSize);
        List<Goods> goodsDTOList = goodsMapper.ListByBusinessCodePad(businessCode);
        return new PageInfo<>(goodsDTOList);
    }



}
